<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('单位专家转移')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row" id="zhuanjiazhuanyi">

            <input name="deptid" th:value="${session.deptid}" type="hidden" id="deptid">
            <input name="currentdeptid" th:value="${currentdeptid}" type="hidden" id="currentdeptid">

            <div class="col-sm-12 search-collapse">
                <div class="col-sm-6">
                    <form>
                        <div class="select-list">
                            <ul>
                                <li>
                                    <label>姓名：</label>
                                    <input type="text" name="xingming" v-model="xingming"/>
                                </li>
                                <li class="sousuo">
                                    <a class="btn btn-primary btn-md" @click="bindZhuanjiaList"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-md" @click=""><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>
                <div class="col-sm-6">
                    <form>
                        <div class="select-list">
                            <ul>
                                <li>
                                    <label>单位名称&nbsp;&nbsp;</label>
                                    <input type="text" name="deptname" v-model="deptname"/>
                                </li>
                                <li class="sousuo">
                                    <a class="btn btn-primary btn-md" @click="bindDeptList"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-md" @click=""><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <div class="col-sm-6" style="padding:20px 10px 0px 10px">
                    <div style="float:left;width:200px;height:34px;line-height:34px;font-size:18px;font-weight: bold;margin-bottom:10px;">单位专家</div>
                    <table class="table table-hover table-primary table-striped">
                        <thead>
                        <tr style="font-weight: bold;height:50px;line-height:50px;">
                            <th style="text-align: center; vertical-align: middle;width:50px;">序号</th>
                            <th style="text-align: center; vertical-align: middle; width:100px;"><input type="checkbox" id="zhuanjia_ckb_all">全选</th>
                            <th style="text-align: center; vertical-align: middle;">专家姓名</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr v-for="(zhuanjiaitem,index) in zhuanjialist"  v-if="zhuanjialist.length > 0">
                            <td style="vertical-align: middle; text-align: center;" v-text="index+1"></td>
                            <td style="vertical-align: middle; text-align: center;"><input type="checkbox" name="zhuanjia_ckb" :value="zhuanjiaitem.zhuanjiaid"></td>
                            <td style="vertical-align: middle; text-align: center;" v-text="zhuanjiaitem.xingming"></td>
                        </tr>
                        <tr v-if="zhuanjialist.length == 0">
                            <td style="text-align: center; vertical-align: middle" colspan="3">查无数据</td>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <div class="col-sm-6" style="padding:20px 10px 0px 10px">
                    <div style="float:left;width:200px;height:34px;line-height:34px;font-size:18px;font-weight: bold">下级单位</div>
                    <button class="btn btn-success btn-rounded btn-md" @click="zhuanyi(olddeptid)" style="float:right;margin-bottom: 10px;">转移至本单位</button>
                    <table class="table table-hover table-primary table-striped">
                        <thead>
                        <tr style="font-weight: bold;height:50px;line-height:50px;">
                            <th style="text-align: center; vertical-align: middle;width:50px;">序号</th>
                            <th style="text-align: center; vertical-align: middle;">单位名称</th>
                            <th style="text-align: center; vertical-align: middle;">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr v-for="(deptitem,index) in deptlist"  v-if="deptlist.length > 0">
                            <td style="vertical-align: middle; text-align: center;" v-text="index+1"></td>
                            <td style="vertical-align: middle; text-align: center;" v-text="deptitem.deptname"></td>
                            <td style="vertical-align: middle; text-align: center;">
                                <button class="btn btn-default btn-md" @click="zhuanyi(deptitem.deptid)">转移</button>
                            </td>
                        </tr>
                        <tr v-if="deptlist.length == 0">
                            <td style="text-align: center; vertical-align: middle" colspan="3">查无数据</td>
                        </tr>
                        </tbody>
                    </table>
                </div>

            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script>
        $("#zhuanjia_ckb_all").on("click",function(){
            if($(this).is(':checked')){
                $('input[name="zhuanjia_ckb"]').each(function(){
                    $(this).prop("checked",true);
                });
            }else{
                $('input[name="zhuanjia_ckb"]').each(function(){
                    $(this).prop("checked",false);
                });
            }
        });

        var vm_zhuanjiazhuanyi = new Vue({
            el: "#zhuanjiazhuanyi",
            data: {
                currentdeptid:$("#currentdeptid").val(),      //传值单位ID，用于左侧查询专家
                deptid:$("#deptid").val(),      //当前登录的新单位ID

                deptlist: [],// 单位列表custom
                zhuanjialist: [],//专家列表custom

                zhuanyizhuanjialist:[],

                //专家查询用字段
                xingming: '',

                //单位查询用字段
                deptname: '',

            },
            created: function () {
                var _this = this;

                _this.bindZhuanjiaList();
                _this.bindDeptList();

            },
            methods: {

                // 根据单位ID查询下级单位
                bindDeptList: function () {
                    var _this = this;

                    var dept_layer = layer.open({type: 3});
                    $.post('/system/deptxinxi/customlist', {
                        parentid: _this.deptid,
                        deptname: _this.deptname,
                        rdm: Math.random()
                    }, function (ppData) {
                        layer.close(dept_layer);

                        if (ppData != null) {
                            if (ppData.result=='1'){
                                var data = ppData.resultContent;
                                _this.deptlist = data;
                            }else{
                                layer.alert(ppData.message);
                            }
                        }
                    }, "json");
                },

                // 绑定专家列表
                bindZhuanjiaList: function () {
                    var _this = this;

                    var zhuanjia_layer = layer.open({type: 3});
                    $.post('/system/zhuanjia/customlist', {
                        deptid: _this.currentdeptid,
                        xingming: _this.xingming,
                        deptlevel: "",
                        gongzuodanwei: "",
                        ruxuannianfen: "",
                        zhuanjiazhuangtai:"",
                        zhuanjiazhuangtaibiandongshijian_kaishi: "",
                        zhuanjiazhuangtaibiandongshijian_jieshu: "",
                        pageindex: 1,
                        pagesize: 9999,
                        rdm: Math.random()
                    }, function (ppData) {
                        layer.close(zhuanjia_layer);

                        if (ppData != null) {
                            if (ppData.result=='1'){

                                //专家列表
                                var data = ppData.resultContent;
                                _this.zhuanjialist = data.zhuanjialist;

                            }else{
                                layer.alert(ppData.message);
                            }
                        }
                    }, "json");
                },

                zhuanyi:function(ppDeptId){
                    var _this = this;

                    var zhuanjiaids = '';

                    var chk_value =[];
                    $('input[name="zhuanjia_ckb"]:checked').each(function(){
                        chk_value.push($(this).val());
                    });
                    if (chk_value.length==0){
                        layer.alert('您还没有选择任何专家！');
                    }else{
                        for(var i=0;i<chk_value.length;i++){
                            zhuanjiaids = zhuanjiaids+chk_value[i]+",";
                        }
                    }

                    var zhuanjia_layer = layer.open({type: 3});
                    $.post('/system/zhuanjiadept/zhuanyi', {
                        zhuanjiaids:zhuanjiaids,
                        deptid:ppDeptId,
                        rdm: Math.random()
                    }, function (ppData) {
                        layer.close(zhuanjia_layer);
                        if (ppData != null) {

                            if (ppData.result == "1") {
                                layer.open({
                                    time: 1000,
                                    btn: [],
                                    content: ppData.resultContent,
                                });

                                _this.refresh();

                            } else {
                                layer.alert(ppData.message);
                            }
                        }
                    }, "json");
                },

                refresh:function(){
                    var _this = this;
                    $('input[name="zhuanjia_ckb"]').prop("checked",false);
                    _this.bindZhuanjiaList();
                }

            }
        })

    </script>
</body>
</html>